package com.controller;

import com.pojo.Likes;
import com.pojo.Result;
import com.service.LikesService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("api/likes")
public class LikesController {

    @Autowired
    private LikesService likesService;

    @PostMapping
    public Result<Void> likeNote(
            @RequestParam Integer userId,
            @RequestParam Integer noteId) {
        return likesService.likeNote(userId, noteId);
    }

    @DeleteMapping
    public Result<Void> unlikeNote(
            @RequestParam Integer userId,
            @RequestParam Integer noteId) {
        return likesService.unlikeNote(userId, noteId);
    }

    @DeleteMapping("/note/{noteId}")
    public Result<Void> unlikeAllByNoteId(@PathVariable Integer noteId) {
        return likesService.unlikeAllByNoteId(noteId);
    }

    @DeleteMapping("/user/{userId}")
    public Result<Void> unlikeAllByUserId(@PathVariable Integer userId) {
        return likesService.unlikeAllByUserId(userId);
    }

    @GetMapping("/status")
    public Result<Boolean> isLiked(
            @RequestParam Integer userId,
            @RequestParam Integer noteId) {
        return likesService.isLiked(userId, noteId);
    }

    @GetMapping("/note/{noteId}/count")
    public Result<Integer> getLikeCountByNoteId(@PathVariable Integer noteId) {
        return likesService.getLikeCountByNoteId(noteId);
    }

    @GetMapping("/user/{userId}/count")
    public Result<Integer> getLikeCountByUserId(@PathVariable Integer userId) {
        return likesService.getLikeCountByUserId(userId);
    }

    @GetMapping("/note/{noteId}")
    public Result<List<Likes>> getLikesByNoteId(@PathVariable Integer noteId) {
        return likesService.getLikesByNoteId(noteId);
    }

    @GetMapping("/user/{userId}")
    public Result<List<Likes>> getLikesByUserId(@PathVariable Integer userId) {
        return likesService.getLikesByUserId(userId);
    }
}